﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.DS
{
    public static partial class status
    {
        public static dynamic getDSTestStatus(int rid)
        {
            var sql = new Sql.SqlDataContext();

            var s = sql.DSStatus.FirstOrDefault(row => row.rid == rid);
            if (s == null) return new
            {
                success = false,
                msg = "状态不存在"
            };

            return (from p in sql.DSProblem
                    from u in sql.User
                    from l in sql.Language
                    where s.rid == rid && p.eid == s.eid && p.pid == s.pid && u.username == s.username && l.code == s.lang
                    select new
                    {
                        success = true,
                        s.rid,
                        s.eid,
                        s.pid,
                        problemTitle = p.title,
                        u.nickname,
                        s.username,
                        submitTime = s.submitTime.toTimeString(),
                        lang = l.title,
                        langCode = s.lang,
                        codeLen = s.code.Length,
                        s.exeTime,
                        s.exeMem,
                        status = Core.status.status2String(s.status),
                        statusCode = s.status,
                        reInfo = Core.status.reCode2String(s.reCode),
                        reCode = Core.status.reCode2Hex(s.reCode),
                        s.ceInfo,
                        p.timeLimit,
                        p.memoryLimit,
                        inputData = functional.HtmlEncode(p.inputData),
                        outputData = functional.HtmlEncode(p.outputData),
                        exeOutput = functional.HtmlEncode(s.exeOutput),
                        p.specialJudge,
                        specialOutput = functional.HtmlEncode(s.specialOutput)
                    }).FirstOrDefault();
        }
    }
}
